<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="项目营业汇总表" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<link href="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="/css/BillList.css" />
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script src="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js"></script>
<script language="javascript">
	function checkDateStr(){
		var startDate=document.getElementById("start_date").value;
		if(startDate==null || startDate==''){
			ShowAlert('提示框','请选择开始日期',200,100);
			return false;
		}else{
			var arr=startDate.split("-");
			if(arr.length==null || arr.length!=3){
				ShowAlert('提示框','开始日期格式不正确',200,100);
				return false;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				ShowAlert('提示框','开始日期格式不正确',200,100);
				return false;
			}
		}
		var endDate=document.getElementById("end_date").value;
		if(endDate==null || endDate==''){
			ShowAlert('提示框','请选择结束日期',200,100);
			return false;
		}else{
			var arr=endDate.split("-");
			if(arr.length==null || arr.length!=3){
				ShowAlert('提示框','结束日期格式不正确',200,100);
				return false;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				ShowAlert('提示框','结束日期格式不正确',200,100);
				return false;
			}
		}
		return true;
	}
	function createPageParaStr(){
		var str="start_date="+encodeURIComponent(document.getElementById("start_date").value);
		str=str+"&end_date="+encodeURIComponent(document.getElementById("end_date").value);
		str=str+"&mt_id="+document.getElementById("mt_id").value;
		str=str+"&pro_name="+encodeURIComponent(document.getElementById("pro_name").value);
		str=str+"&est_id="+document.getElementById("est_id").value;
		str=str+"&est_name="+encodeURIComponent(document.getElementById("est_name").value);
		str=str+"&mng_name="+encodeURIComponent(document.getElementById("mng_name").value);
		str=str+"&desi_name="+encodeURIComponent(document.getElementById("desi_name").value);
		str=str+"&foll_name="+encodeURIComponent(document.getElementById("foll_name").value);
		str=str+"&crea_name="+encodeURIComponent(document.getElementById("crea_name").value);
		str=str+"&ts_id="+document.getElementById("ts_id").value;
		
		return str;
	}
	
	function createProgramParaStr(){
		var str="start_date="+encodeURIComponent(document.getElementById("hid_start_date").value);
		str=str+"&end_date="+encodeURIComponent(document.getElementById("hid_end_date").value);
		str=str+"&mt_id=${mtId}";
		str=str+"&pro_name="+encodeURIComponent(document.getElementById("hid_pro_name").value);
		str=str+"&est_id=${estId}";
		str=str+"&est_name="+encodeURIComponent(document.getElementById("hid_est_name").value);
		str=str+"&mng_name="+encodeURIComponent(document.getElementById("hid_mng_name").value);
		str=str+"&desi_name="+encodeURIComponent(document.getElementById("hid_desi_name").value);
		str=str+"&foll_name="+encodeURIComponent(document.getElementById("hid_foll_name").value);
		str=str+"&crea_name="+encodeURIComponent(document.getElementById("hid_crea_name").value);
		str=str+"&ts_id=${tsId}";
		
		return str;
	}
	function doSearch(){
		var str;
		if(IsAdvSearch){//高级
			str="search_type=1";
			if(document.getElementById("cb_order_date").checked){
				if(checkDateStr()){
					str=str+"&cb_order_date=1";
				}else{
					return;
				}
			}
			if(document.getElementById("cb_mt").checked){
				var mtId=document.getElementById("mt_id").value;
				if(mtId==null || mtId=="" || mtId=="0"){
					ShowAlert('请选择项目类型','',200,100);
					return;
				}
				str=str+"&cb_mt=1";
			}
			if(document.getElementById("cb_pro").checked){
				var proName=document.getElementById("pro_name").value.trim();
				if(proName==null || proName==""){
					ShowAlert('提示框','请输入材质',200,100);
					return;
				}
				str=str+"&cb_pro=1";
			}
			if(document.getElementById("cb_est").checked){
				var estId=document.getElementById("est_id").value;
				if(estId==null || estId=="" || estId=="0"){
					ShowAlert('提示框','请选择客户',200,100);
					return;
				}
				str=str+"&cb_est=1";
			}
			if(document.getElementById("cb_mng").checked){
				var mngName=document.getElementById("mng_name").value.trim();
				if(mngName==null || mngName==""){
					ShowAlert('提示框','请输入业务员姓名',200,100);
					return;
				}
				str=str+"&cb_mng=1";
			}
			if(document.getElementById("cb_desi").checked){
				var desiName=document.getElementById("desi_name").value.trim();
				if(desiName==null || desiName==""){
					ShowAlert('提示框','请输入设计员姓名',200,100);
					return;
				}
				str=str+"&cb_desi=1";
			}
			if(document.getElementById("cb_foll").checked){
				var follName=document.getElementById("foll_name").value.trim();
				if(follName==null || follName==""){
					ShowAlert('提示框','请输入跟单人姓名',200,100);
					return;
				}
				str=str+"&cb_foll=1";
			}
			if(document.getElementById("cb_crea").checked){
				var creaName=document.getElementById("crea_name").value.trim();
				if(creaName==null || creaName==""){
					ShowAlert('提示框','请输入开单人姓名',200,100);
					return;
				}
				str=str+"&cb_crea=1";
			}
			if(document.getElementById("cb_ts").checked){
				var tsId=document.getElementById("ts_id").value;
				if(tsId==null || tsId=="" || tsId=="0"){
					ShowAlert('提示框','请选择帐套',200,100);
					return;
				}
				str=str+"&cb_ts=1";
			}
		}else{//快速
			str="search_type=2";
			if(!checkDateStr()){
				return;
			}
		}
		var paraStr=createPageParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		window.location="/business/MtBusinessCount.ihtm?"+str;
	}
	function getSearchCondition(){
		var searchType="${searchType}";
		var str="search_type="+searchType;
		if(searchType=="1"){//高级
			<c:if test="${cbOrderDate=='1'}">str=str+"&cb_order_date=1";</c:if>
			<c:if test="${cbMt=='1'}">str=str+"&cb_mt=1";</c:if>
			<c:if test="${cbPro=='1'}">str=str+"&cb_pro=1";</c:if>
			<c:if test="${cbEst=='1'}">str=str+"&cb_est=1";</c:if>
			<c:if test="${cbMng=='1'}">str=str+"&cb_mng=1";</c:if>
			<c:if test="${cbDesi=='1'}">str=str+"&cb_desi=1";</c:if>
			<c:if test="${cbFoll=='1'}">str=str+"&cb_foll=1";</c:if>
			<c:if test="${cbCrea=='1'}">str=str+"&cb_crea=1";</c:if>
			<c:if test="${cbTs=='1'}">str=str+"&cb_ts=1";</c:if>
		}else{//快速
			
		}
		var paraStr=createProgramParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		return str;
	}
	function doAutoCheck(objId){
		document.getElementById(objId).checked=true;
	}
	function doGo(pageIndex){
		var str=getSearchCondition();
		window.location="/business/MtBusinessCount.ihtm?"+str+"&current_page="+pageIndex;
	}
	
	function doJump(pageIndex){
		if(window.event.keyCode==13){
			doGo(pageIndex);
		}
	}
	function DoubleClick(it){
		
	}
	function doDownload(){
		var str=getSearchCondition();
		window.location="/business/MtBusinessCount.ihtm?content_type=EXCEL&"+str;
	}
	function doCancel(){
		window.close();
	}
	function doInit(){
		Window_Onload();
	}
	function checkInput(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function selectEstName(){
		var url="/base/EstablishmentListForSelect.ihtm?type=CLIENT";
		ShowIframe("选择客户",url,900,500,"selectEstNameCallBack()",1024,600);
	}
	function selectEstNameCallBack(){
		if(popRetVal!=null){
			document.getElementById("est_id").value=popRetVal[0];
			document.getElementById("est_name").value=popRetVal[1];
			doAutoCheck("cb_est");
		}
	}
	function selectStafferName(objId,checkObjId){
		var url="/base/StafferMainForSelect.ihtm";
		var cb="selectStafferNameCallBack('"+objId+"','"+checkObjId+"')";
		ShowIframe("选择员工",url,800,500,cb);
	}
	function selectStafferNameCallBack(objId,checkObjId){
		if(popRetVal!=null){
			var arr=popRetVal.split(";");
			document.getElementById(objId).value=arr[1];
			doAutoCheck(checkObjId);
		}
	}
	function setDate(type){
		var d=new Date();
		var startStr="";
		var endStr="";
		if(type=="CURRENT_MONTH"){
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-01";
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="PREVIEW_MONTH"){
			d=new Date(d.getFullYear(),d.getMonth(),1);
			d.setDate(d.getDate()-1);
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-1";
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="TODAY"){
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="YESTERDAY"){
			d.setDate(d.getDate()-1);
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}
		document.getElementById("start_date").value=startStr;
		document.getElementById("end_date").value=endStr;
		doAutoCheck("cb_order_date");
	}
	function showDetail(mtId,proName,priceType){
		var url="/business/BusinessBillItemSearchResult.ihtm?search_type=1&cb_examine=1&examined=Y&cb_make_type=1&make_type="+mtId+"&cb_pr=1&pr="+priceType;
		//if(proName!=null && proName!=""){
			url=url+"&cb_product=1&product="+encodeURIComponent(proName);
		//}
		<c:if test="${searchType!='1' || cbOrderDate=='1'}">url=url+"&cb_order_date=1&start_date=${startDate}&end_date=${endDate}";</c:if>
		<c:if test="${cbEst=='1'}">url=url+"&cb_est=1&est_id=${estId}&est_name="+encodeURIComponent(document.getElementById("hid_est_name").value);</c:if>
		<c:if test="${cbMng=='1'}">url=url+"&cb_mng=1&mng_name="+encodeURIComponent(document.getElementById("hid_mng_name").value);</c:if>
		<c:if test="${cbDesi=='1'}">url=url+"&cb_desi=1&desi_name="+encodeURIComponent(document.getElementById("hid_desi_name").value);</c:if>
		<c:if test="${cbFoll=='1'}">url=url+"&cb_foll=1&foll_name="+encodeURIComponent(document.getElementById("hid_foll_name").value);</c:if>
		<c:if test="${cbCrea=='1'}">url=url+"&cb_crea=1&crea_name="+encodeURIComponent(document.getElementById("hid_crea_name").value);</c:if>
		<c:if test="${cbTs=='1'}">url=url+"&cb_ts=1&ts_id=${tsId}";</c:if>
		showWin(1024,600,url);
	}
</script>
</head>
<body>
<div class="Wrap"><!-- 页面主框架 -->
    
	<div id="ListContainer" class="Container"><!-- 主体容器 -->
	    
	    <!-- 标题栏 -->
	    <div class="Heading BillIcon">
	        <div class="HeadingContent">
	            <h1>项目营业汇总表</h1>
	            <span class="Note">统计指定期间全部客户或者指定客户的各个项目平均单价与接单金额</span>
	        </div>
	    </div>
	
		<!-- 主内容 -->
		<div class="Content">
	        <!-- 筛选控件栏 -->
	        <div class="FilterBar ClearFix">
	            <div class="SearchIcon"></div>
	            <span class="fl">
	            	<table class="MoreOption" cellpadding="0" cellspacing="0">
	            		<th class="c1" width="80px">
	            			<input type="checkbox" name="cb_order_date" id="cb_order_date" <c:if test="${cbOrderDate=='1' || searchType=='2'}">checked="true"</c:if> style="visibility:hidden;" />
	            			日期
	            		</th>
	            		<td width="360px">
	            			<input type="text" class="TextBox Datetime" maxlength="15" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_order_date');" id="start_date" name="start_date" value="<c:out value="${startDate}" />">
							<input type="hidden" id="hid_start_date" value="<c:out value="${startDate}" />">
							<img src="/images/calendar.gif" class="imgIconButton" onClick="displayCalendar(document.getElementById('start_date'),'yyyy-mm-dd',this,false,'doAutoCheck(\'cb_order_date\')');">
							至
							<input type="text" class="TextBox Datetime" maxlength="15" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_order_date');" id="end_date" name="end_date" value="<c:out value="${endDate}" />">
							<input type="hidden" id="hid_end_date" value="<c:out value="${endDate}" />">
							<img src="/images/calendar.gif" class="imgIconButton" onClick="displayCalendar(document.getElementById('end_date'),'yyyy-mm-dd',this,false,'doAutoCheck(\'cb_order_date\')');">
				            <a href="javascript:setDate('CURRENT_MONTH');">本月</a>
							<a href="javascript:setDate('TODAY');">今天</a>
							<a href="javascript:setDate('YESTERDAY');">昨天</a>
							<a href="javascript:setDate('PREVIEW_MONTH');">上月</a>
	            		</td>
	            	</table>
	            </span>
	            <span class="fr">
	            	<a href="javascript:;" id="lnkMoreOption">更多查询选项</a>
		  			<input type="button" value=" 查 询" onClick="doSearch();" id="sSearchButton" name="sSearchButton" class="buttom search-but">
		  			<input type="button" value=" 导 出" onClick="doDownload();" class="buttom search-out" id="sDownloadButton" name="sDownloadButton" <c:if test="${currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';NO_EXPO;')!=-1}">disabled="true"</c:if>>
	            </span>
				<div id="dvMoreOptionBox" class="MoreOptionBox" style="display:none;">
					<table class="MoreOption" cellpadding="0" cellspacing="0">
						<tr>
							<th class="c1" width="80px">
			        			<input type="checkbox" name="cb_mt" id="cb_mt" <c:if test="${cbMt=='1'}">checked="true"</c:if>>
			        			项目类型
			        		</th>
			        		<td class="c1" width="260px">
			        			<select name="mt_id" id="mt_id" onFocus="doAutoCheck('cb_mt');">
							  		<option value="0">==请选择==</option>
							  		<commonTag:createSelectTree list="${makeTypeList}" emptyOption="0" defaultValue="${mtId}" />
						  		</select>
			    			</td>
			    		</tr>
			    		<tr>
							<th class="c1">
			        			<input type="checkbox" name="cb_pro" id="cb_pro" <c:if test="${cbPro=='1'}">checked="true"</c:if>>
			        			材质
			        		</th>
			        		<td class="c1">
			        			<input type="text" class="TextBox" maxlength="50" name="pro_name" id="pro_name" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_pro');" value="<c:out value="${proName}" />">
								<input type="hidden" id="hid_pro_name" value="<c:out value="${proName}" />">
			    			</td>
			    		</tr>
			    		<tr>
							<th class="c1">
			        			<input type="checkbox" name="cb_mng" id="cb_mng" <c:if test="${cbMng=='1'}">checked="true"</c:if>>
			        			业务员
			        		</th>
			        		<td class="c1">
			        			<input type="text" class="TextBox" maxlength="15" name="mng_name" id="mng_name" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_mng');" value="<c:out value="${mngName}" />" >
	                        	<img src="/images/make-a.gif" class="imgIconButton" onClick="selectStafferName('mng_name','cb_mng');" />
	                        	<input type="hidden" id="hid_mng_name" value="<c:out value="${mngName}" />">
			    			</td>
			    		</tr>
			    		<tr>
							<th class="c1">
			        			<input type="checkbox" name="cb_desi" id="cb_desi" <c:if test="${cbDesi=='1'}">checked="true"</c:if>>
			        			设计员
			        		</th>
			        		<td class="c1">
			        			<input type="text" class="TextBox" maxlength="15" name="desi_name" id="desi_name" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_desi');" value="<c:out value="${desiName}" />" >
	                        	<img src="/images/make-a.gif" class="imgIconButton" onClick="selectStafferName('desi_name','cb_desi');" />
	                        	<input type="hidden" id="hid_desi_name" value="<c:out value="${desiName}" />">
			    			</td>
			    		</tr>
			    		<tr>
							<th class="c1">
			        			<input type="checkbox" name="cb_foll" id="cb_foll" <c:if test="${cbFoll=='1'}">checked="true"</c:if>>
			        			跟单员
			        		</th>
			        		<td class="c1">
			        			<input type="text" class="TextBox" maxlength="15" name="foll_name" id="foll_name" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_foll');" value="<c:out value="${follName}" />" >
	                        	<img src="/images/make-a.gif" class="imgIconButton" onClick="selectStafferName('foll_name','cb_foll');" />
	                        	<input type="hidden" id="hid_foll_name" value="<c:out value="${follName}" />">
			    			</td>
			    		</tr>
			    		<tr>
							<th class="c1">
			        			<input type="checkbox" name="cb_crea" id="cb_crea" <c:if test="${cbCrea=='1'}">checked="true"</c:if>>
			        			开单人
			        		</th>
			        		<td class="c1">
			        			<input type="text" class="TextBox" maxlength="15" name="crea_name" id="crea_name" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_crea');" value="<c:out value="${creaName}" />">
								<img class="imgIconButton" src="/images/make-a.gif" onClick="selectStafferName('crea_name','cb_crea');" />
								<input type="hidden" id="hid_crea_name" value="<c:out value="${creaName}" />">
			    			</td>
			    		</tr>
			    		<tr>
							<th class="c1">
			        			<input type="checkbox" name="cb_est" id="cb_est" <c:if test="${cbEst=='1'}">checked="true"</c:if>>
			        			客户
			        		</th>
			        		<td class="c1">
			        			<input type="text" class="TextBox readonly" readonly="true" name="est_name" id="est_name" value="<c:out value="${estName}" />" >
								<img class="imgIconButton" src="/images/make-a.gif" onClick="selectEstName();" />
								<input type="hidden" id="est_id" value="<c:out value="${estId}" />">
								<input type="hidden" id="hid_est_name" value="<c:out value="${estName}" />">
			    			</td>
			    		</tr>
			    		<tr>
							<th class="c1">
			        			<input type="checkbox" name="cb_ts" id="cb_ts" <c:if test="${cbTs=='1'}">checked="true"</c:if>>
			        			帐套
			        		</th>
			        		<td class="c1">
			        			<select name="ts_id" id="ts_id" onFocus="doAutoCheck('cb_ts');">
							  		<option value="0">==请选择账套==</option>
							  		<c:forEach var="item" items="${tsList}">
							  		<option value="${item.id}" <c:if test="${tsId==item.id}">selected</c:if>>${item.title}</option>
							  		</c:forEach>
						  		</select>
			    			</td>
			    		</tr>
			    	</table>
			    	
					<div class="OptionOrderBy">
	                    <span class="fr"><a href="javascript:;" id="lnkHiddenOption">隐藏查询选项</a></span>
	                </div>
				</div>
			</div>
			
			<!-- 提示信息显示栏 -->
	        <div class="MsgBar">
	            <%@include file="../inc/AlertMsg.jsp"%>
	        </div>
	        
	        <!-- 上栏 分页、操作等 -->
			<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';NO_TOTA;')==-1}">
	        <div class="TopToolBar">
	            <table class="ListNoteInfo" cellpadding="0" cellspacing="0">
	            	<tr>
	                	<td>金额合计：${costTotal}元</td>
	            	</tr>
	            </table>
			</div>
			</c:if>

		    <div class="table-list">
		        <table width="100%">
					<tr>
						<th width="20%">项目类型</th>
						<th width="25%">材质</th>
						<th width="10%">单位</th>
						<th width="15%">数量</td>
						<th width="15%">平均单价</th>
						<th width="15%">金额</th>
					</tr>
					<c:forEach var="item" items="${qr.list}" varStatus="i">
					<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
					<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
					<c:set var="defaultFontColor" value="#000000" />
					<c:if test="${item[9]=='N'}"><c:set var="defaultFontColor" value="red" /></c:if>
					<tr class="${trClass}" index="${i.index+1}" style="color:${defaultFontColor};cursor:pointer;" defaultFontColor="${defaultFontColor}" ondblclick='javascript:DoubleClick(this)' onClick='javascript:ClickCheck(this)' onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
						<td>
							${item[0]}
							<input type="radio" name='query_checkbox' value="" style="display:none">
						</td>
						<td>${item[1]}</td>
						<td>${item[2]}</td>
						<td><div align="right">${item[3]}</div></td>
						<td><div align="right">${item[4]}</div></td>
						<td><div align="right"><c:if test="${item[9]=='Y'}"><a href="javascript:showDetail(${item[10]},'<c:out value="${item[1]}" />','${item[6]}');"></c:if>${item[5]}<c:if test="${item[9]=='Y'}"></a></c:if></div></td>
					</tr>
					</c:forEach>
				</table>
			</div>
			
			<!-- 底栏 分页、操作等 -->
	        <div class="BottomToolBar ClearFix">
			    <%@include file="../inc/Pages.jsp"%>
	        </div>
			
		</div>
	</div>
</div>
</body>
</html>
<script type="text/javascript">
	function ChangeWindowSize( container, maxWidth ){
	    setTimeout( function(){
	        var w1 = document.documentElement.clientWidth-40;
	        if( w1>maxWidth ) w1 = maxWidth;
	        else if( w1<870 ) w1 = 860;
	        container.style.width = w1+'px';
	    }, 300 );
	}
	var IsAdvSearch = false;
	(function(){
		doInit();
	    var ListContainer = document.getElementById('ListContainer');
	    ChangeWindowSize( ListContainer, 2020 );    // 超过 1280 的最大 1260 ，不全部铺满
	
	    var lnkMoreOption   = document.getElementById('lnkMoreOption');
	    var lnkHiddenOption = document.getElementById('lnkHiddenOption');
	    lnkMoreOption.onclick = function(){
	    	IsAdvSearch = true;
	        document.getElementById('dvMoreOptionBox').style.display = 'block';
	        document.getElementById('cb_order_date').style.visibility = 'visible';
	        this.style.visibility = 'hidden';
	    };
	    lnkHiddenOption.onclick = function(){
	    	IsAdvSearch = false;
	        document.getElementById('dvMoreOptionBox').style.display = 'none';
	        document.getElementById('cb_order_date').style.visibility = 'hidden';
	        lnkMoreOption.style.visibility = 'visible';
	    };
	})();
</script>
